
public class ScaleDriver {

	/**
	 * @param args
	 */
	public static void main(String[] args) 
	{
		IPowerControl powerCtrl = new PowerControlStub();
		IDisplay display = new ConsoleDisplay();
		ISoundDevice soundDevice = new ConsoleSoundDevice();
		
		// create a scale object with auto shut down after 5 seconds
		Scale scale = new Scale(powerCtrl, display, soundDevice, 5000);
		
		
		// weigh an object
		Weighable weight = new Weighable(1250.456677);
		scale.weigh(weight);
		// change units back and forth
		scale.setUnits(WeightUnits.POUNDS);
		scale.setUnits(WeightUnits.GRAMS);
		scale.setUnits(WeightUnits.POUNDS);
		// weigh another object
		weight = new Weighable(350);
		scale.weigh(weight);
		// suspend this thread for 2 sec to prove the resetting of the auto control feature
		suspend(2000);
		// change units
		scale.setUnits(WeightUnits.GRAMS);
		// set tare
		scale.setTare();
		suspend(500);
		weight = new Weighable(450);
		scale.weigh(weight); // should say 100 grams, because the tare is 350 grams
		scale.setUnits(WeightUnits.POUNDS);
		scale.setUnits(WeightUnits.GRAMS);
		weight = new Weighable(0);
		scale.weigh(weight);
		scale.setTare();
	}
	
	private static void suspend(int ms)
	{
		try {
			Thread.sleep(ms);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
